﻿using System;
using System.Web.Configuration;

namespace VioletDevelopmentLaboratory.Net.Web.Configuration
{
	public sealed class UrlMappingsSectionManager : ConfigurationManagerBase
	{
		private UrlMappingsSection section;

		public UrlMappingsSectionManager()
		{
			this.section = (UrlMappingsSection)base.GetConfigurationSection("system.web/urlMappings");
		}

		public void Modify(bool isEnabled)
		{
			this.section.IsEnabled = isEnabled;
			this.Save();
		}
		public UrlMappingsSection GetUrlMappingsSection()
		{
			return this.section;
		}


		public void AddUrlMapping(string url, string mappedUrl)
		{
			this.section.UrlMappings.Add(new UrlMapping(url, mappedUrl));
			this.Save();
		}
		public void RemoveUrlMapping(string url)
		{
			this.section.UrlMappings.Remove(url);
			this.Save();
		}
		public void ClearUrlMappings()
		{
			this.section.UrlMappings.Clear();
			this.Save();
		}
		public UrlMapping GetUrlMapping(string url)
		{
			return this.section.UrlMappings[url];
		}
		public UrlMappingCollection GetUrlMappingCollection()
		{
			return this.section.UrlMappings;
		}
	}
}
